import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Question15 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int m = in.nextInt();

        int[] a = new int[n];
        int[] s = new int[m];

        int minm_a = Integer.MAX_VALUE;
        int index_minm_a = 0;
        int maxm_a = Integer.MIN_VALUE;
        int index_maxm_a = 0;

        int minm_s = Integer.MAX_VALUE;
        int index_minm_s = 0;
        int maxm_s = Integer.MIN_VALUE;
        int index_maxm_s = 0;


        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();

            if (a[i] < minm_a) {
                minm_a = a[i];
                index_minm_a = i;
            }

            if (a[i] > maxm_a) {
                maxm_a = a[i];
                index_maxm_a = i;
            }
        }
        
        for (int i = 0; i < m; i++) {
            s[i] = in.nextInt();
            
            if (s[i] < minm_s) {
                minm_s = s[i];
                index_minm_s = i;
            }

            if (s[i] > maxm_s) {
                maxm_s = s[i];
                index_maxm_s = i;
            }
        }

        int ret = 0;

        if (maxm_s > maxm_a) {
            if (minm_s < minm_a) {
                ret = n + m - 1;
            }
            else {
                int index = index_minm_a;

                ret = Math.max(index, n - index - 1) + m;
            }
        }
        else {
            if (minm_s > minm_a) {
                ret = Math.abs(index_minm_a - index_maxm_a);
            }
            else {
                int index = index_maxm_a;

                ret = Math.max(index, n - index - 1) + m;
            }
        }

        System.out.println(ret);
    }
}